#ifndef __GYT_AEC_H__
#define __GYT_AEC_H__

#include <stdint.h>
#include <stdbool.h>
#include <alsa/asoundlib.h>
#include "adt_typedef_user.h"
#include "iaecg4.h"

#define VER_MAJOR          1
#define VER_MINOR          0
#define VER_PATCH          3

#define DAEMON             /* 守护进程 */
//#define PRINT_ERL

typedef enum {

    PCMALSA,
    PCMFILE,
    PCMRTP

} type_pcm_t;

struct pcm_device
{
    snd_pcm_t        *handle_capture;    /* PCM capture 设备操作句柄 */
    snd_pcm_t        *handle_playback;   /* PCM playback设备操作句柄 */
    snd_pcm_format_t  format;            /* 数据格式 */

    uint16_t          channels;          /* 音轨数目 */
    uint32_t          sample_rate;       /* 采样率 */
    size_t            bits_per_sample;   /* 一个采样点的位数 */
    size_t            bytes_per_frame;   /* 一个帧的字节数 */

    snd_pcm_uframes_t period_size;       /* 一个周期内的帧个数 */
    snd_pcm_uframes_t buffer_size;       /* 系统buffer的帧个数 */

    uint8_t          *period_buf;        /* 存放从wav文件读取的一个周期的数据 */
};
typedef struct pcm_device pcm_device_t;

struct adt_aec 
{
    pcm_device_t  pcm;
    IAECG4_Handle hAEC;

    bool enabled;
    int  bypass_mode;
    char device_name[16];
    type_pcm_t pcm_src;
    type_pcm_t pcm_dest;

    int  is_ec_dump;
    FILE *echofile;
    FILE *reffile;
    FILE *stereofile;
    FILE *cleanfile;

    int  signal_src;
    int  gpio_number;
};
typedef struct adt_aec adt_aec_t;

struct handfree_src
{
    const char *name;
    int  (*init)(void);
    void (*handler)(void);
};
typedef struct handfree_src *handfree_src_t;

/* Global variable */
adt_aec_t g_aec;

/* Function */
void LOG(const char *format, ...);
int  parse_config_file(const char *path);    /* Obsolete */

#endif /* __GYT_AEC_H__ */